<?php
require_once 'BaseMySQLDAO.php';

class GamePromotionDAO extends BaseMySQLDAO {

    public function __construct($context) {
        parent::__construct($context, 'game_promotion');
    }

    public function getGamePromotion() {
        return $this->getGameByStatus(1);
    }

    public function getGameGuide() {
        return $this->getGameByStatus(2);
    }

    public function getGameByStatus($status) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM game_promotion WHERE status = :status ORDER BY `order` ASC";
            $param = array(':status' => $status);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }

    public function getGamePromotionById($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM game_promotion WHERE id = :id";
            $param = array(':id' => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }

    public function getTelcoPromotion() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM telco_promotion WHERE expire_date > NOW() ";
            $param = array();
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
}
?>